home *** CD-ROM | disk | FTP | other *** search
/ An Introduction to Progr…l Basic 6.0 (4th Edition) / An Introduction to Programming using Visual Basic 6.0.iso / PROGRAMS / CH7 / 7-5-2.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1998-09-19  |  8.1 KB  |  280 lines

  1. VERSION 5.00
  2. Begin VB.Form frmMeal 
  3.    Caption         =   "Nutrition in a Meal"
  4.    ClientHeight    =   3828
  5.    ClientLeft      =   1068
  6.    ClientTop       =   1548
  7.    ClientWidth     =   5112
  8.    BeginProperty Font 
  9.       Name            =   "MS Sans Serif"
  10.       Size            =   7.8
  11.       Charset         =   0
  12.       Weight          =   700
  13.       Underline       =   0   'False
  14.       Italic          =   0   'False
  15.       Strikethrough   =   0   'False
  16.    EndProperty
  17.    LinkTopic       =   "Form1"
  18.    PaletteMode     =   1  'UseZOrder
  19.    ScaleHeight     =   3828
  20.    ScaleWidth      =   5112
  21.    Begin VB.TextBox txtQnty 
  22.       Height          =   285
  23.       Index           =   9
  24.       Left            =   2280
  25.       TabIndex        =   22
  26.       Top             =   3480
  27.       Width           =   495
  28.    End
  29.    Begin VB.TextBox txtQnty 
  30.       Height          =   285
  31.       Index           =   8
  32.       Left            =   2280
  33.       TabIndex        =   21
  34.       Top             =   3120
  35.       Width           =   495
  36.    End
  37.    Begin VB.TextBox txtQnty 
  38.       Height          =   285
  39.       Index           =   7
  40.       Left            =   2280
  41.       TabIndex        =   20
  42.       Top             =   2760
  43.       Width           =   495
  44.    End
  45.    Begin VB.TextBox txtQnty 
  46.       Height          =   285
  47.       Index           =   6
  48.       Left            =   2280
  49.       TabIndex        =   19
  50.       Top             =   2400
  51.       Width           =   495
  52.    End
  53.    Begin VB.TextBox txtQnty 
  54.       Height          =   285
  55.       Index           =   5
  56.       Left            =   2280
  57.       TabIndex        =   18
  58.       Top             =   2040
  59.       Width           =   495
  60.    End
  61.    Begin VB.TextBox txtQnty 
  62.       Height          =   285
  63.       Index           =   4
  64.       Left            =   2280
  65.       TabIndex        =   17
  66.       Top             =   1680
  67.       Width           =   495
  68.    End
  69.    Begin VB.TextBox txtQnty 
  70.       Height          =   285
  71.       Index           =   3
  72.       Left            =   2280
  73.       TabIndex        =   16
  74.       Top             =   1320
  75.       Width           =   495
  76.    End
  77.    Begin VB.TextBox txtQnty 
  78.       Height          =   285
  79.       Index           =   2
  80.       Left            =   2280
  81.       TabIndex        =   15
  82.       Top             =   960
  83.       Width           =   495
  84.    End
  85.    Begin VB.TextBox txtQnty 
  86.       Height          =   285
  87.       Index           =   1
  88.       Left            =   2280
  89.       TabIndex        =   14
  90.       Top             =   600
  91.       Width           =   495
  92.    End
  93.    Begin VB.PictureBox picAnalysis 
  94.       Height          =   2055
  95.       Left            =   2880
  96.       ScaleHeight     =   2004
  97.       ScaleWidth      =   2124
  98.       TabIndex        =   1
  99.       Top             =   1200
  100.       Width           =   2175
  101.    End
  102.    Begin VB.CommandButton cmdAnalyze 
  103.       Caption         =   "Analyze Meal Nutrition"
  104.       Height          =   375
  105.       Left            =   2880
  106.       TabIndex        =   0
  107.       Top             =   720
  108.       Width           =   2175
  109.    End
  110.    Begin VB.TextBox txtQnty 
  111.       Height          =   285
  112.       Index           =   0
  113.       Left            =   2280
  114.       TabIndex        =   4
  115.       Top             =   240
  116.       Width           =   495
  117.    End
  118.    Begin VB.Label lblFood 
  119.       Alignment       =   1  'Right Justify
  120.       Caption         =   "(food name)"
  121.       Height          =   255
  122.       Index           =   9
  123.       Left            =   0
  124.       TabIndex        =   13
  125.       Top             =   3480
  126.       Width           =   2175
  127.    End
  128.    Begin VB.Label lblFood 
  129.       Alignment       =   1  'Right Justify
  130.       Caption         =   "(food name)"
  131.       Height          =   255
  132.       Index           =   8
  133.       Left            =   0
  134.       TabIndex        =   12
  135.       Top             =   3120
  136.       Width           =   2175
  137.    End
  138.    Begin VB.Label lblFood 
  139.       Alignment       =   1  'Right Justify
  140.       Caption         =   "(food name)"
  141.       Height          =   255
  142.       Index           =   7
  143.       Left            =   0
  144.       TabIndex        =   11
  145.       Top             =   2760
  146.       Width           =   2175
  147.    End
  148.    Begin VB.Label lblFood 
  149.       Alignment       =   1  'Right Justify
  150.       Caption         =   "(food name)"
  151.       Height          =   255
  152.       Index           =   6
  153.       Left            =   0
  154.       TabIndex        =   10
  155.       Top             =   2400
  156.       Width           =   2175
  157.    End
  158.    Begin VB.Label lblFood 
  159.       Alignment       =   1  'Right Justify
  160.       Caption         =   "(food name)"
  161.       Height          =   255
  162.       Index           =   5
  163.       Left            =   0
  164.       TabIndex        =   9
  165.       Top             =   2040
  166.       Width           =   2175
  167.    End
  168.    Begin VB.Label lblFood 
  169.       Alignment       =   1  'Right Justify
  170.       Caption         =   "(food name)"
  171.       Height          =   255
  172.       Index           =   4
  173.       Left            =   0
  174.       TabIndex        =   8
  175.       Top             =   1680
  176.       Width           =   2175
  177.    End
  178.    Begin VB.Label lblFood 
  179.       Alignment       =   1  'Right Justify
  180.       Caption         =   "(food name)"
  181.       Height          =   255
  182.       Index           =   3
  183.       Left            =   0
  184.       TabIndex        =   7
  185.       Top             =   1320
  186.       Width           =   2175
  187.    End
  188.    Begin VB.Label lblFood 
  189.       Alignment       =   1  'Right Justify
  190.       Caption         =   "(food name)"
  191.       Height          =   255
  192.       Index           =   2
  193.       Left            =   0
  194.       TabIndex        =   6
  195.       Top             =   960
  196.       Width           =   2175
  197.    End
  198.    Begin VB.Label lblFood 
  199.       Alignment       =   1  'Right Justify
  200.       Caption         =   "(food name)"
  201.       Height          =   255
  202.       Index           =   1
  203.       Left            =   0
  204.       TabIndex        =   5
  205.       Top             =   600
  206.       Width           =   2175
  207.    End
  208.    Begin VB.Label lblQnty 
  209.       Caption         =   "Quantity in Meal"
  210.       Height          =   255
  211.       Left            =   2040
  212.       TabIndex        =   2
  213.       Top             =   0
  214.       Width           =   1455
  215.    End
  216.    Begin VB.Label lblFood 
  217.       Alignment       =   1  'Right Justify
  218.       Caption         =   "(food name)"
  219.       Height          =   255
  220.       Index           =   0
  221.       Left            =   0
  222.       TabIndex        =   3
  223.       Top             =   240
  224.       Width           =   2175
  225.    End
  226. Attribute VB_Name = "frmMeal"
  227. Attribute VB_GlobalNameSpace = False
  228. Attribute VB_Creatable = False
  229. Attribute VB_PredeclaredId = True
  230. Attribute VB_Exposed = False
  231. Dim nutName(1 To 5) As String            'nutrient names
  232. Dim nutTable(1 To 10, 1 To 5) As Single  'nutrient values for each food
  233. Private Sub cmdAnalyze_Click()
  234.   'Determine the nutritional content of a meal
  235.   Dim quantity(1 To 10) As Single  'amount of food in meal
  236.   Call GetAmounts(quantity())
  237.   Call ShowData(quantity())
  238. End Sub
  239. Private Sub Form_Load()
  240.   Dim i As Integer, j As Integer, foodName As String
  241.   'Fill arrays; assign label captions
  242.   Open App.Path & "\NUTTABLE.TXT" For Input As #1
  243.   For i = 1 To 5
  244.     Input #1, nutName(i)
  245.   Next i
  246.   For i = 1 To 10
  247.     Input #1, foodName
  248.     lblFood(i - 1).Caption = foodName
  249.     For j = 1 To 5
  250.       Input #1, nutTable(i, j)
  251.     Next j
  252.   Next i
  253.   Close #1
  254. End Sub
  255. Private Sub GetAmounts(quantity() As Single)
  256.   Dim i As Integer
  257.   'Obtain quantities of foods consumed
  258.   For i = 1 To 10
  259.     quantity(i) = Val(txtQnty(i - 1).Text)
  260.   Next i
  261. End Sub
  262. Private Sub ShowData(quantity() As Single)
  263.   Dim col As Integer, row As Integer
  264.   Dim amount As Single, nutWid As Single
  265.   'Display amount of each component
  266.   picAnalysis.Cls
  267.   picAnalysis.Print "This meal contains the"
  268.   picAnalysis.Print "following quantities"
  269.   picAnalysis.Print "of these nutritional"
  270.   picAnalysis.Print "components:"
  271.   picAnalysis.Print
  272.   For col = 1 To 5
  273.     amount = 0
  274.     For row = 1 To 10
  275.       amount = amount + quantity(row) * nutTable(row, col)
  276.     Next row
  277.     picAnalysis.Print nutName(col) & ":"; Tab(16); amount
  278.   Next col
  279. End Sub
  280.